<template>
  <a-modal
    title="回复消息"
    style="top: 20px;"
    :width="900"
    v-model="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
  >
    <a-form :form="form">
      <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="接收人"
      >
        <a-input disabled v-decorator="['toUser',{rules: [{ required: true, message: '接收人不能为空' }]}]"/>
      </a-form-item>

      <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="标题"
      >
        <a-input disabled v-decorator="['subject',{rules: [{ required: true, message: '标题不能为空' }]}]"/>
      </a-form-item>

      <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="内容"
      >
        <wang-editor @change="()=>{}" v-decorator="['content', { rules: [{ required: true, message: '内容不能为空' }] }]" v-if="visible"/>
      </a-form-item>

    </a-form>

  </a-modal>
</template>

<script>
import WangEditor from '@/components/Editor/WangEditor'
import { replyinit, reply } from '@/api/system'
export default {
  components: {
    WangEditor
  },
  data () {
    return {
      visible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this)

    }
  },
  methods: {
  open (id) {
      this.visible = true
      this.form.resetFields()
      this.initReplayInfo(id)
    },
    initReplayInfo (id) {
      replyinit(id).then(res => {
        this.form.setFieldsValue({ toUser: res.data.toUser, subject: res.data.subject })
      })
    },
    handleSubmit (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          this.confirmLoading = true
          reply(values).then(res => {
            if (res.status === 1) {
              this.$message.success(res.message)
               this.form.resetFields()
               this.visible = false
               this.$emit('ok')
            } else {
              this.$message.error(res.res.message)
            }
          }).finally(() => {
            this.confirmLoading = false
          })
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
/deep/ .w-e-toolbar {
  flex-wrap: wrap;
}
</style>
